//
//  OrderCompleteUpLoadImageTableViewCell.m
//  SsehMaster
//
//  Created by 杨阳 on 2018/11/13.
//  Copyright © 2018 yinlong. All rights reserved.
//

#import "OrderCompleteUpLoadImageTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface OrderCompleteUpLoadImageTableViewCell()

@property (nonatomic,strong) UIImageView * clickImageView;

@property (nonatomic,strong) NSIndexPath * tIndex;

@end

@implementation OrderCompleteUpLoadImageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.clickImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"uploadImage_sseh"]];
    self.clickImageView.userInteractionEnabled = YES;
    self.clickImageView.contentMode = UIViewContentModeScaleToFill;
    [self.imageView1 addSubview:self.clickImageView];
    [self.clickImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImageView:)];
    [self.clickImageView addGestureRecognizer:tap];
    
}

-(void)clickImageView:(UITapGestureRecognizer *)tap{
    
    if (_imageViewClick) {
        _imageViewClick(self.tIndex);
    }
}

-(void)configData:(SsehPublicModel *)model andIndex:(NSIndexPath *)index{
    
    self.tIndex = index;
    //1 上传图片 2 显示图片
    if ([model.statyStr isEqualToString:@"1"]) {
        self.clickImageView.hidden = NO;
        [self uploadPic:model];
    }else{
        self.clickImageView.hidden = YES;
        [self showPic:model];
    }
    
    
}

-(void)showPic:(SsehPublicModel *)model{
    
    NSArray * imageArr = [model.infoStr componentsSeparatedByString:@","];
    if (!kArrayIsEmpty(imageArr)) {
        if (imageArr.count >= 3) {
            self.bottomViewHeight.constant = 84.0f;
            self.bottomView.hidden = NO;
            
        }else{
            self.bottomViewHeight.constant = 1.0f;
            self.bottomView.hidden = YES;
        }
        for (NSInteger i = 0; i < imageArr.count; i++) {
            NSString * imageUrl = imageArr[i];
            UIImageView * imageView = [[UIImageView alloc]init];
            switch (i) {
                case 0:
                    imageView = self.imageView1;
                    break;
                case 1:
                    imageView = self.imageView2;
                    break;
                case 2:
                    imageView = self.imageView3;
                    break;
                case 3:
                    imageView = self.imageView4;
                    break;
                case 4:
                    imageView = self.imageView5;
                    break;
                case 5:
                    imageView = self.imageView6;
                    break;
                    
                default:
                    break;
            }
            [imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"ssehLogo"]];
        }
    }
    
}


-(void)uploadPic:(SsehPublicModel *)model{
    
    if (model.imageArr.count >= 3) {
        
        self.bottomViewHeight.constant = 84.0f;
        self.bottomView.hidden = NO;
        self.imageView4.hidden = NO;
        self.imageView5.hidden = NO;
        self.imageView6.hidden = NO;
        
    }else{
        self.bottomViewHeight.constant = 1.0f;
        self.bottomView.hidden = YES;
        self.imageView4.hidden = YES;
        self.imageView5.hidden = YES;
        self.imageView6.hidden = YES;
    }
    
    switch (model.imageArr.count) {
        case 0:
            self.clickImageView.hidden = NO;
            [self.imageView1 addSubview:self.clickImageView];
            [self.clickImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
            }];
            break;
        case 1:
            self.clickImageView.hidden = NO;
            [self.imageView2 addSubview:self.clickImageView];
            [self.clickImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
            }];
            break;
        case 2:
            self.clickImageView.hidden = NO;
            [self.imageView3 addSubview:self.clickImageView];
            [self.clickImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
            }];
            break;
        case 3:
            self.clickImageView.hidden = NO;
            [self.imageView4 addSubview:self.clickImageView];
            [self.clickImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
            }];
            break;
        case 4:
            self.clickImageView.hidden = NO;
            [self.imageView5 addSubview:self.clickImageView];
            [self.clickImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
            }];
            break;
        case 5:
            self.clickImageView.hidden = NO;
            [self.imageView6 addSubview:self.clickImageView];
            [self.clickImageView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
            }];
            break;
        case 6:
            self.clickImageView.hidden = YES;
            break;
            
        default:
            break;
    }
    
    for (NSInteger i = 0; i < model.imageArr.count; i++) {
        
        if ([model.imageArr[i] isKindOfClass:[UIImage class]]) {
            
            UIImage * image = model.imageArr[i];
            switch (i) {
                case 0:
                    self.imageView1.image = image;
                    break;
                case 1:
                    self.imageView2.image = image;
                    break;
                case 2:
                    self.imageView3.image = image;
                    break;
                case 3:
                    self.imageView4.image = image;
                    break;
                case 4:
                    self.imageView5.image = image;
                    break;
                case 5:
                    self.imageView6.image = image;
                    break;
                    
                default:
                    break;
            }
            
        }
        
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
